function deepCopy(obj,hash = new WeakMap()) {
  if (obj === null || obj === undefined) return obj;
  else if (typeof obj === 'function') {
    return function() {
      return obj.apply(this, arguments);
    }
  }
  // 如果是基本数据类型，直接返回
  else if (typeof obj !== 'object') return obj;
  // 如果是日期类型
  else if (obj.constructor === Date) return new Date(obj);
  // 如果是正则
  else if (obj.constructor === RegExp) return new RegExp(obj);
  // 防止循环引用
  else if (hash.has(obj)) return hash.get(obj);
  const cloneObj = Array.isArray(obj) ? [] : {};

  // 递归拷贝
  for (let key in obj) {
    if (obj.hasOwnProperty(key)) {
      cloneObj[key] = deepCopy(obj[key], hash);
    }
  }
  hash.set(obj, cloneObj);
  return cloneObj;
}

const original = {
  number: 1,
  bool: false,
  string: 'string',
  symbol: Symbol('sym'),
  obj: { nested: 'object' },
  array: [1, 2, 3],
  func: function() { console.log(this); },
  date: new Date(),
  regex: /regex/g
};
const cloned = deepCopy(original);
console.log(cloned);
cloned.func();